package com.quanshu.exchange.support.utils;

import android.view.View;

/**
 * 防止重复点击
 */
public class NoDoubleClickListener implements View.OnClickListener {

    private long lastClickTime = 0;
    private int delayTime = 0;
    private View.OnClickListener realListener;

    public NoDoubleClickListener(View.OnClickListener realListener) {
        this(300, realListener);
    }

    public NoDoubleClickListener(int delayTime, View.OnClickListener realListener) {
        this.realListener = realListener;
        this.delayTime = delayTime;
    }

    @Override
    public void onClick(View v) {
        long currentTime = System.currentTimeMillis();
        if (currentTime - lastClickTime > delayTime) {
            lastClickTime = currentTime;
            realListener.onClick(v);
        }
    }
}
